package org.jim.server.command.handler;

import org.jim.core.ImChannelContext;
import org.jim.core.ImPacket;
import org.jim.core.exception.ImException;
import org.jim.core.packets.pub.consts.Command;
import org.jim.core.packets.pub.HeartbeatBody;
import org.jim.core.packets.RespBody;
import org.jim.server.command.AbstractCmdHandler;
import org.jim.server.command.CommandHandler;
import org.jim.server.protocol.ProtocolManager;

/**
 *
 */
@CommandHandler(cmd = Command.COMMAND_HEARTBEAT_REQ)
public class HeartbeatReqHandler extends AbstractCmdHandler {
    @Override
    public ImPacket handler(ImPacket packet, ImChannelContext channelContext) throws ImException {
        RespBody heartbeatBody = new RespBody(Command.COMMAND_HEARTBEAT_REQ).setData(new HeartbeatBody(Protocol.HEARTBEAT_BYTE));
        ImPacket heartbeatPacket = ProtocolManager.Converter.respPacket(heartbeatBody, channelContext);
        return heartbeatPacket;
    }

    @Override
    public Command command() {
        return Command.COMMAND_HEARTBEAT_REQ;
    }
}
